package org.simp.core.request;


import java.util.HashMap;
import java.util.Map;

import org.simp.core.body.SimpBody;
import org.simp.core.head.SimpHeader;
import org.simp.core.message.SimpMessage;
import org.simp.session.SimpSession;

/**
 * @author zhuhaitao at 2014-5-23
 *
 * 
 */
public class SimpRequestWarper implements SimpRequest{

	protected SimpSession session;
	
	protected SimpMessage simpMessage;
	
	protected Map<String,Object> attributes = new HashMap<String,Object>();
	
	public SimpRequestWarper(SimpMessage simpMessage,SimpSession simpSession){
		this.simpMessage = simpMessage;
		this.session = simpSession;
	}
	@Override
	public SimpSession getSession() {
		// TODO Auto-generated method stub
		return session;
	}

	@Override
	public SimpMessage getSimpMessage() {
		return simpMessage;
	}
	@Override
	public String getObjAddress() {
		// TODO Auto-generated method stub
		return simpMessage.getHead().getObjAddress();
	}
	@Override
	public String getSrcAddress() {
		// TODO Auto-generated method stub
		return simpMessage.getHead().getSrcAddress();
	}
	@Override
	public void setObjAddress(String objAddress) {
		simpMessage.getHead().setObjAddress(objAddress);
		
	}
	@Override
	public void setSrcAddress(String srcAddress) {
		// TODO Auto-generated method stub
		simpMessage.getHead().setSrcAddress(srcAddress);
	}
	@Override
	public void setAttribute(String key, Object value) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public Object getAttribute(String key) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public SimpHeader getHead() {
		// TODO Auto-generated method stub
		return simpMessage.getHead();
	}
	@Override
	public SimpBody getBody() {
		// TODO Auto-generated method stub
		return simpMessage.getBody();
	}
	@Override
	public void setBody(SimpBody body) {
		simpMessage.setBody(body);
		
	}
	@Override
	public String getHead(String key) {
		// TODO Auto-generated method stub
		return simpMessage.getHead().getHeadParam(key);
	}
	@Override
	public boolean hasBody() {
		return simpMessage.hasBody();
	}
	@Override
	public void write(SimpMessage message) {
		message.getHead().setSerial(getHead().getSerial());
		message.setObjAddress(getSrcAddress());
		message.setSrcAddress(getObjAddress());
		session.write(message);
		
	}



}
